package com.loren.demo04.publish_subscribe.publisher;

import com.loren.demo04.publish_subscribe.subscriber.MessageSubscriber;
import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@AllArgsConstructor
public class MessagePublisher {

    private final StringRedisTemplate stringRedisTemplate;

    /**
     * 发布订阅模式 - 发布
     */
    @GetMapping("/publish")
    public String publish(@RequestParam("message") String message) {
        this.stringRedisTemplate.convertAndSend(MessageSubscriber.CHANNEL_NAME, message);
        return "success";
    }
}
